home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14413 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: ix.netcom.com!netnews
  2. From: jdmorris@ix.netcom.com (Jason D. Morris)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Why does this work?
  5. Date: Sat, 30 Mar 1996 03:32:43 GMT
  6. Organization: Netcom
  7. Message-ID: <315caa28.2883596@nntp.ix.netcom.com>
  8. References: <DoxvnA.L0C@mail.auburn.edu> <4jejr9$7a8@atlas.tncnet.com>
  9. NNTP-Posting-Host: pon-mi2-25.ix.netcom.com
  10. X-NETCOM-Date: Fri Mar 29  7:31:51 PM PST 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. >>#include <iostream.h>
  14. >>#include <ctype.h>
  15. >>
  16. >>void main(void)
  17. >> {
  18. >>   char letter;
  19. >>
  20. >>   while (! cin.eof())
  21. >>     {
  22. >>       letter = cin.get();
  23. >>       letter = toupper(letter);
  24. >>       cout << letter;
  25. >>     }
  26. >> }
  27. >>
  28. >>Why does this work!?!?  It seems to reserve storage for only one 
  29. >>character in letter, but outputs a whole line at a time.  Feel free to 
  30. >>flame my stupidity, but please satisfy my curiosity (I'm really not this 
  31. >>clueless, I promise!!)
  32.  
  33. Remember that i/o using cin/cout, and iostreams in general, is
  34. buffered. Therefore, what you type in at the console is held in a
  35. buffer until you press the enter key.  At that point, the loop starts
  36. doing its work, reading input from the buffer and checking for EOF.
  37.  
  38. Jason
  39.  
  40.